﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Resources;
using System.Collections;
using System.Reflection;

namespace BMS.Syncro.Devices.Utility
{
    public class ZKEMDeviceUtil
    {
        #region Properties
        private ResourceManager resource = null;
        private const string resxFile = "BMS.Syncro.Devices.Utility.ZKEMErrorCodesResource";
        #endregion Properties

        #region Methods
        /// <summary>
        /// Get a value from the resource file
        /// </summary>
        /// <param name="key">Key for the resource</param>
        /// <returns>Value of the resource</returns>
        public string GetValueFromResource(string key)
        {
            if (resource == null)
                LoadResourceFile();

            return resource.GetString(key);
        }

        /// <summary>
        /// Load the resource file ZKEMErrorCodesResource
        /// </summary>
        internal void LoadResourceFile()
        {
            // Create the resource manager.
            Assembly assembly = this.GetType().Assembly;

            //ResFile.Strings -> <Namespace>.<ResourceFileName i.e. Strings.resx> 
            ResourceManager resource = new ResourceManager(resxFile, assembly);
        }

        /// <summary>
        /// Get the error message description if the device has some kind of error
        /// </summary>
        /// <param name="deviceManager">Device manager ZKEM. Object type: CZKEMClass</param>
        /// <returns>Empty if everything is ok or the message in error case</returns>
        public string GetErrorMessageFromDevice(zkemkeeper.CZKEMClass deviceManager)
        {
            int errorId = 1; // The id 1 is Operation is correct
            deviceManager.GetLastError(ref errorId);
            if (errorId != 1)
                return this.GetValueFromResource(errorId.ToString());

            return string.Empty;
        }
        #endregion Methods
    }
}
